      SUBROUTINE RDCAT2(LUCATLG,
     *   NTARGS,KTARGID,TARGNAMES,KTARGTYP,MAXPARM,TARGPARM,
     *   NFOUND,LUERR,IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE IS PART OF THE TARGET CATALOGUE READER. IT IS USED WHEN
C THE CALLER HAS ASKED TO HAVE ALL CATALOGUE TARGET INFO RETURNED.
C
C***********************************************************************
C
C BY C PETRUZZO, GSFC/742, 12/84, 3/85, 7/85
C    MODIFIED.....
C
C***********************************************************************
C
      REAL*8    TARGPARM(MAXPARM,1) ! ACTUAL= TARGPARM(MAXPARM,NTARGS)
      INTEGER*4 KTARGID(1)          ! ACTUAL= KTARGID(NTARGS)
      INTEGER*4 KTARGTYP(1)         ! ACTUAL= KTARGTYP(NTARGS)
      CHARACTER*16 TARGNAMES(1)     ! ACTUAL= TARGNAMES(NTARGS)
C
      CHARACTER*16 NAME
C
      IERR = 0
C
C THIS ROUTINE SHOULD BE CALLED ONLY WHEN KTARGID(1) = 'ALL'.
C
      IF(KTARGID(1).NE.'ALL') THEN
        TYPE *,'RDCAT2 ERROR. PROGRAMMER ERROR. SEE CODE.'
        STOP   'RDCAT2 ERROR. PROGRAMMER ERROR. SEE CODE.'
        END IF
C
C LOAD KTARGID ARRAY FROM THE CATALOGUE. NTARGS MUST BE LARGE ENOUGH
C TO HOLD ALL CATALOGUE ENTRIES EXCEPT THOSE WITH ZERO/NEGATIVE
C TARGET ID'S OR TARGET TYPES.
C
      REWIND LUCATLG
      CALL MTXSETI4(KTARGID,0,NTARGS,1)
C
C    READ TO THE END OF THE FILE, COUNTING THE NUMBER OF RECORDS
C    PRESENT, IGNORING THOSE WITH ZERO/NEGATIVE ID'S AND TYPES. SAVE
C    ID'S AS WE GO.
C
      ITARG = 0
      DO I=1,9999999
C      READ THE DUM VARIABLE IN CASE THERE ARE PARAMETERS EXTENDING
C      BEYOND THE FIRST LINE FOR THE TARGET BEING INPUT.  THE READ
C      STATEMENT ENDS AT THE SLASH CHARACTER IN THE RECORD.
        READ(LUCATLG,*,END=75) KID,NAME,KTYPE,(DUM,IDUM=1,999)
        IF(KID.GT.0 .AND. KTYPE.GT.0) THEN
          ITARG = ITARG + 1
          IF(ITARG.LE.NTARGS) KTARGID(ITARG) = KID
          END IF
        END DO
C
   75 CONTINUE
C
C    ERROR CHECK. IF NTARGS IS TOO SMALL, SET UP FOR ERROR RETURN.
C
      IF(ITARG.GT.NTARGS) THEN
        IERR = 8
        CALL MTXSETR8(TARGPARM,0.D0,MAXPARM,NTARGS)
        DO I=1,NTARGS
          KTARGID(I) = 0
          KTARGTYP(I) = -8
          TARGNAMES(I) = 'RDCAT ERROR 8'
          NFOUND = -ITARG
          END DO
        IF(LUERR.GT.0) WRITE(LUERR,1001) LUCATLG,IABS(NFOUND)
 1001   FORMAT(/,
     *   ' RDCAT2 ERROR CONDITION.  CATALOGUE FILE UNIT=',I3/,
     *   ' CALLER WANTED TO LOAD THE ENTIRE TARGET CATALOGUE INTO THE'/,
     *   ' TARGET ARRAYS, BUT DID NOT ALLOW ENOUGH ARRAY SPACE. YOU'/,
     *   ' NEED TO CALL THE CATALOGUE READER(RDCAT) WITH NTARGS',
     *       ' GT/EQ ',I5/)
        END IF
C
      RETURN
      END
